import { request } from '@/utils/request';

// API 接口地址
const API = {
  list: '/system/dict/type/list',
  detail: '/system/dict/type',
  refresh: '/system/dict/type/refreshCache',
  option: '/system/dict/type/optionselect',
};

// 定义接口类型
interface DictTypeQuery {
  pageNum?: number;
  pageSize?: number;
  dictName?: string;
  dictType?: string;
  status?: string;
  [key: string]: any;
}

interface DictTypeData {
  dictId?: number | string;
  dictName?: string;
  dictType?: string;
  status?: string;
  remark?: string;
  [key: string]: any;
}

// 查询字典类型列表
export function getList(query?: DictTypeQuery): Promise<any> {
  return request.get({
    url: API.list,
    params: query,
  });
}

// 查询字典类型详细
export function getInfo(dictId: string | number): Promise<any> {
  return request.get({
    url: `${API.detail}/${dictId}`,
  });
}

// 新增字典类型
export function add(data: DictTypeData): Promise<any> {
  return request.post({
    url: API.detail,
    data,
  });
}

// 修改字典类型
export function edit(data: DictTypeData): Promise<any> {
  return request.put({
    url: API.detail,
    data,
  });
}

// 删除字典类型
export function Delete(dictId: string | number): Promise<any> {
  return request.delete({
    url: `${API.detail}/${dictId}`,
  });
}

// 刷新字典缓存
export function refreshCache(): Promise<any> {
  return request.delete({
    url: API.refresh,
  });
}

// 获取字典选择框列表
export function optionselect(): Promise<any> {
  return request.get({
    url: API.option,
  });
}
